package org.lanqiao.music.system.service.impl;

import org.lanqiao.music.common.dto.SingerDTO;
import org.lanqiao.music.system.entity.Singer;
import org.lanqiao.music.system.dao.SingerDao;
import org.lanqiao.music.system.service.SingerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.PageHelper;

import java.util.List;

/**
 * (Singer)表服务实现类
 *
 * @author makejava
 * @since 2024-08-15 20:53:50
 */
@Service
@CacheConfig(cacheNames = "user1")
public class SingerServiceImpl implements SingerService {
    @Autowired
    private SingerDao singerDao;

    /**
     * 通过ID查询单条数据
     *
     * @param singerId 主键
     * @return 实例对象
     *
     */


    @Override
    public Singer queryById(Integer singerId) {
        return this.singerDao.queryById(singerId);
    }

    /**
     * 分页查询
     *
     * @param dto 筛选条件
     * @return 查询结果
     */


    @Override
    @Cacheable(key = "{#dto.singerLocation, #dto.singerName, #dto.singerSex}")
//    @Cacheable(keyGenerator = "myKeyGenerator") 生成策略
    public PageInfo<Singer> queryAllSinger(SingerDTO dto) {
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        PageInfo page = new PageInfo<>(this.singerDao.queryAllSinger(dto));
        return page;
    }

    /**
     * 新增数据
     *
     * @param record 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(Singer record) {
        return this.singerDao.insert(record);

    }

    @Override
    public int insertBatch(List<Singer> entities) {
        return singerDao.insertBatch(entities);
    }

    /**
     * 修改数据
     *
     * @param singer 实例对象
     * @return 实例对象
     */
    @Override
    public int update(Singer singer) {
        return singerDao.update(singer);
    }

    /**
     * 通过主键删除数据
     *
     * @param singerId 主键
     * @return 是否成功
     */
    @Override
    public int deleteById(Integer singerId) {
        return this.singerDao.deleteById(singerId);
    }


    /*
    * 批量删除
    * */
    @Override
    public int deleteBatch(Integer[] singerIds) {
        return singerDao.deleteBatch(singerIds);
    }
}
